//
//  FQDLabPapersFeedCellItemProvider.m
//  FakeQDaily
//
//  Created by mewxiv on 9/17/16.
//  Copyright © 2016 Xensius. All rights reserved.
//

#import "FQDLabPapersFeedCellItemProvider.h"
#import "FQDRestModel.h"
#import "QDailyAPI.h"
#import "FQDLabFeedCellItem.h"

#import "YYModel.h"

static NSString *const kLabPaperFeed = @"lab_papers";

@interface FQDLabPapersFeedCellItemProvider ()

@property (nonatomic, strong) NSArray *papers;

@end

@implementation FQDLabPapersFeedCellItemProvider

- (void)getCellItems:(NSString *)cursorKey completion:(QDailyAPICompleteBlock)completion
{
    [[QDailyAPI sharedAPI] getLabPaperList:cursorKey completion:completion];
}

- (void)parseResponse:(id)response isLatest:(BOOL)isLatest
{
    self.papers = [NSArray yy_modelArrayWithClass:[FQDFeed class]
                                             json:response[@"feeds"]];
}

- (void)populateNewCellItemsTo:(NSMutableArray *)originalCellItems
{
    for (FQDFeed *feed in self.papers) {
        NSInteger genre = feed.post.genre;
        if (genre == FQDPostGenreVote || genre == FQDPostGenreOpinion) {
            FQDLabFeedCellItem *cellItem = [FQDLabFeedCellItem cellItemWithRestModel:feed];
            cellItem.showSubscription = NO;
            [originalCellItems addObject:cellItem];
        }
    }
}

- (NSString *)cacheId
{
    return kLabPaperFeed;
}

@end
